package com.xkcyy.demo.springcloud.simple.userservice.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * UseController
 *
 * @author xkcyy
 * @date 2022/4/28
 **/
@RestController
public class UseController {
    @PostMapping("/user/listusers")
    public List<String> listUsers(@RequestParam String groupId, @RequestBody Map<String,Object> values){
        ArrayList<String> arr = new ArrayList<>();
        arr.add("123");
        arr.add("456");
        for (Map.Entry<String, Object> x : values.entrySet()) {
            arr.add(x.getKey() + ":" + x.getValue());
        }
        return  arr;
    }

    @PostMapping(value = "/user/file")
    //@RequestMapping(value = "/user/file", method = RequestMethod.POST)
    public List<String> file(FileUploadCommand command) throws IOException {
        List<String> stringlist=new ArrayList<>();
        stringlist.add( command.getFile().getBytes().length + "");
        return stringlist;
    }
    @GetMapping("/user/test")
    public void test(HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.write("<form method='post' action='http://localhost:10030/user/file'> <input name='file' type='file'/> <input type='submit'></form>");
    }
}
